package org.example.pms.controller;

import org.example.pms.domain.EpitopeDetectionResult;
import org.example.pms.service.EpitopeDetectionResultService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/epitopeDetectionResults")
public class EpitopeDetectionResultController {

    @Resource
    private EpitopeDetectionResultService epitopeDetectionResultService;

    /**
     * 根据id查询
     *
     * @param id 自增id
     * @return 表位结果
     */
    @GetMapping("/{id}")
    public EpitopeDetectionResult getEpitopeDetectionResult(@PathVariable Integer id) {
        EpitopeDetectionResult epitopeDetectionResults = epitopeDetectionResultService.getEpitopeDetectionResultById(id);
        return epitopeDetectionResults;
    }

    /**
     * 根据patientId查询表位结果集
     *
     * @param patientId 患者id
     * @return 患者的表位结果集
     */
    @GetMapping("/results/{patientId}")
    public List<EpitopeDetectionResult> getEpitopeDetectionResultsByPatientId(@PathVariable Integer patientId) {
        List<EpitopeDetectionResult> epitopeDetectionResults = epitopeDetectionResultService.getEpitopeDetectionResultsByPatientId(patientId);
        return epitopeDetectionResults;
    }

    /**
     * 添加表位结果
     *
     * @param epitopeDetectionResult 表位结果
     * @return 插入表位结果的id
     */
    @PostMapping()
    public Integer getEpitopeDetectionResultsByPatientId(@RequestBody EpitopeDetectionResult epitopeDetectionResult) {
        Integer id = epitopeDetectionResultService.addEpitopeDetectionResult(epitopeDetectionResult);
        if (id < 1) return null;
        return id;
    }
}
